﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAC.sqlHelper;

namespace Bussiness
{
    /// <summary>
    /// 报警相关参数描述类
    /// </summary>
    public class RelationAlarm
    {
        string errMsg = "";

        /// <summary>
        /// 参数
        /// </summary>
        public string ParaID { get; set; }
        /// <summary>
        /// 参数描述
        /// </summary>
        public string ParaDescription { get; set; }
        /// <summary>
        /// 报警描述
        /// </summary>
        public string AlarmDescription { get; set; }
        /// <summary>
        /// 上限
        /// </summary>
        public string HighLimit { get; set; }
        /// <summary>
        /// 下限
        /// </summary>
        public string LowLimit { get; set; }
        /// <summary>
        /// 参考值
        /// </summary>
        public string CKValue { get; set; }
        /// <summary>
        /// 获取报警描述
        /// </summary>
        /// <param name="paraID"></param>
        /// <returns></returns>
        public System.Data.DataTable GetDescription(string paraDESC)
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            string sql = "SELECT PARAID,PARADESC FROM T_RELATION_ALARM WHERE ALARMDESC='" + paraDESC + "'";
            //DB2Provider.DataLink link = new DB2Provider.DataLink();
            try
            {
                dt = DBsql.RunDataTable(sql, out errMsg);//link.ExcuteRetureTable(sql);;
                return dt;
            }
            catch (Exception ex)
            {
                throw new Exception("数据库被占用，请先关闭DB2数据库！");
            }
        }
        /// <summary>
        /// 插入数据
        /// </summary>
        public void Insert()
        {
            string sql = "INSERT INTO T_RELATION_ALARM(PARAID,PARADESC,ALARMDESC,CKVALUE) VALUES ('" + ParaID + "','" + ParaDescription + "','" + AlarmDescription + "'," + CKValue + ")";
            if (CKValue == "" || CKValue == null)
                sql = "INSERT INTO T_RELATION_ALARM(PARAID,PARADESC,ALARMDESC) VALUES ('" + ParaID + "','" + ParaDescription + "','" + AlarmDescription + "')";
            //DB2Provider.DataLink link = new DB2Provider.DataLink();
            //link.Excute(sql);

            DBsql.RunNonQuery(sql, out errMsg);

        }
        /// <summary>
        /// 返回报警
        /// </summary>
        /// <returns></returns>
        public System.Data.DataTable GetAlarm()
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            string sql = "SELECT * FROM T_RELATION_ALARM ";
            //DB2Provider.DataLink link = new DB2Provider.DataLink();
            dt = DBsql.RunDataTable(sql, out errMsg);//link.ExcuteRetureTable(sql);
            return dt;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id_key"></param>
        public void Delete(int id_key)
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            string sql = "DELETE FROM T_RELATION_ALARM WHERE ID_KEY= " + id_key;
            //DB2Provider.DataLink link = new DB2Provider.DataLink();
            //link.Excute(sql);

            DBsql.RunNonQuery(sql, out errMsg);
        }





    }
}
